;
(function () {
  new Vue({
    el: '#renting',
    data: {
      rratMenu: [{
          name: '可售',
          code: 'SALE',
          num: 0
        },
        {
          name: '认购',
          code: 'SUB',
          num: 0
        },
        {
          name: '签约',
          code: 'SIGN',
          num: 0
        },
        {
          name: '锁定',
          code: 'LOCK',
          num: 0
        },
        {
          name: '认筹',
          code: 'IDTFY',
          num: 0
        },
      ],
      rratMenuSelect: [],
      projectIdSelect: [],
      buildingsSelect: [],
      nums: 14,
      buildingMes1: {
        totalWpCount: 1,
        totalStCount: 0
      },
      buildingMes2: {
        totalWpCount: 1,
        totalStCount: 0
      },
      buildingMes3: {
        totalWpCount: 1,
        totalStCount: 0
      },
      permissions: JSON.parse(window.localStorage.getItem('permissions')),
      floors: [], // 楼层信息
      buildings: [], // 项目楼宇
      leftTab: [
        '全部',
        '空置单元',
        '即将到期',
        '即将履约',
        '自用'
      ],
      rightTab: [
        '单元视图',
        '工位视图',
        '车位视图',
        '平面图'
      ],
      selectedLeftTabItem: "全部",
      selectedrightTabItem: "单元视图",
      unitsKey: 'all',
      unitsData: {
        'all': [],
        'kz': [],
        'dq': [],
        'lv': [],
        'zy': [],
        'sale': [],
        'sub': [],
        'sign': [],
        'lock': [],
        'idtfy': []
      },
      stData: {
        'all': [],
        'kz': [],
        'dq': [],
        'lv': [],
        'zy': []
      },
      wpData: {
        'all': [],
        'kz': [],
        'dq': [],
        'lv': [],
        'zy': []
      },
      positionData: [],
      floorData: [{
        floor: ''
      }],
      pmtData: [],
      imageUrl: '',
      // 单元
      unitTotalNum: 0,
      kzUnitTotalNum: 0,
      dqUnitTotalNum: 0,
      lvUnitTotalNum: 0,
      zyUnitTotalNum: 0,
      // 车位
      stTotalNum: 0,
      kzStTotalNum: 0,
      dqStTotalNum: 0,
      lvStTotalNum: 0,
      zyStTotalNum: 0,
      // 工位
      wpTotalNum: 0,
      kzWpTotalNum: 0,
      dqWpTotalNum: 0,
      lvWpTotalNum: 0,
      zyWpTotalNum: 0,
      projectId: null,
      projectName: null,
      buildingId: null,
      buildingName: null,
      unitView: true, // 单元视图
      stView: false, // 车位视图
      wpView: false, // 工位视图
      pmtView: false, // 平面图视图
      unitkb: false, // 单元看板
      stkb: false, // 车位看板
      wpkb: false, // 工位看板
      onlyUnitKb: false, // 横条单元看板
      isShowPositionDetail: false, // 车位工位详情
      noWp: false, // 无工位展示
      noSt: false, // 无车位展示
      flexStyle: {},
      unitDetailStyle: {
        'width': '810px',
      },
      permission: {
        'createPermission': false,
        'checkPermission': false
      },
      unitDetails: [],
      selectedUnitId: null,
      buUnitPopTab: [
        '房源详情',
        '在租客户',
        '图文描述',
        '初步意向',
        '意向信息',
        '关联合同',
        '相关文件'
      ],
      intentlist: [],
      selectedbuUnitTabItem: '房源详情',
      isShowBuUnitDetail: false, // 普通单元详情
      rentFlag: true, // 房源信息
      houseInfoFlag: true, // 房源信息
      imageFontFlag: false, // 图文描述
      intention: false, // 初步意向
      fileFlag: false, //相关文件
      contractFlag: false, // 相关合同
      yxFlag: false,
      createContractFlag: true, // 创建合同按钮权限
      checkContractFlag: true, // 查看合同详情权限
      baseFacility: [], // 基础设施
      unitPositionImgArr: [], // 单元楼层落位图
      unitPlainImgArr: [], // 单元平面图
      consImgsArr: [], // 装修图纸
      innerImgsArr: [], // 室内自拍图
      associatedContracts: [], // 关联合同
      businessTypesList: [],
      selectedBusinessTypes: [], // 选中的业态类型
      businessFlag: false,
      businessTextFlag: true,
      baseWidth: null,
      baseHeight: null,
      naturalWidth: null,
      naturalHeight: null,
      intentionList:[],
      scale: 0.1,
      addNum: 0,
      contractFile: [],
      curDataPanel: '签约维度',
      stwpFlag: false,
      selectedPositionType: null,
      selectedPositionIds: [],
      selectedPositionIdInfos: [],
      rentUnitInfo: {},
      projectList: [],
      //远洋GB
      isDisplayRentPop: true,
      queryRRAT: localStorage.getItem('userMes'),
      empty_q: '',
      empty_h: '',
      deadline_q: '',
      deadline_h: '',
      //组合
      groupId: null,
      groupOneData: [],
      groupTwoData: [],
      groupThreeData: [],
      selectedGroupData: ['所有组合'],
      decoration: [],
      // 在租客户
      rentInfo: '',
    },
    filters: {
      undefined: function (item) {
        if (!item) return '--'
        return item
      },
      formatNum: function (item) {
        if (item === undefined) return '--'
        return hlNumberUtil.formatNum(item)
      },
      formatTwoDecimal: function (item) {
        return hlNumberUtil.formatTwoDecimal(item)
      },
      floorName: function (val) {
        if (!val) return
        if (val.length <= 3) {
          return '(' + val + ')'
        }
        if (val.length > 3) {
          return '(' + val.substring(0, 2) + '...)'
        }
      },
      formatBusinessType: function (item) {
        let result;
        switch (item) {
          case 'BU':
            result = '普通单元'
            break;
          case 'ST':
            result = '停车场'
            break;
          case 'WP':
            result = '联合办公'
            break;
          default:
            result = '--'
        }
        return result
      },
      formatDate: function (time) {
        if (time === undefined) return '--'
        return hlDateUtil.formatUTCDate(time, 'yyyy-MM-dd')
      },
      contractAuditState: function (state) {
        return hlCodeConvert.contractAuditState(state)
      },
      unitDecoration: function (item) {
        return hlCodeConvert.decoration(item)
      },
      unitOrientation: function (item) {
        return hlCodeConvert.orientation(item)
      }
    },
    watch: {
      stwpFlag(val) {
        if (val) {
          this.buUnitPopTab.unshift('租赁情况')
        }
        if (!val) {
          this.buUnitPopTab.splice(0, 1)
        }
      }
    },
    computed: {
      typeval() {
        let val;
        this.decoration.map(item => {
          if (this.unitDetails.decorationType == item.code) {
            val = item.memo
          }
        })
        return val
      }
    },
    methods: {
      //获取装修水平类型列表
      getDecorationtypes: function () {
        var self = this;
        hlhttp.get({
          url: 'unit/decoration_types',
          success: function (res) {
            self.decoration = res;
          }
        })
      },

      rratBack(arr, e, item) {
        this.rratMenuSelect = []
        arr.map(obj => {
          if (obj.code == item.code) {
            this.rratMenuSelect = [item.code]
          }
        })
      },


      selectedBuildinged(arr) {
        this.selectedBuilding(arr[0].projectId, arr[0].buildingId, arr[0].names, arr[0].projectName)
        this.buildingId = arr[0].buildingId
        this.buildingName = arr[0].names
      },
      // 获取所有项目
      getProject() {
        hlhttp.get({
          url: 'user/projects',
          success: (res) => {
            res = hlArrayUtil.removeRepeat(res, 'projectId')

            this.projectList = hlArrayUtil.replaceData(res, [{
              key: 'projectName',
              rKey: 'name'
            }, {
              key: 'projectId',
              rKey: 'code'
            }]);

            this.projectIdSelect = [res[0].projectId]
						if (hlUrlUtil.GetQueryString('projectId')) {
							this.projectIdSelect = [hlUrlUtil.GetQueryString('projectId')]
						}

						var temp;
						this.projectList.map(item => {
							if (item.projectId == this.projectIdSelect[0]) {
								temp = item;
							}
						})

            this.getGroupPrimaryData([temp])
          }
        })
      },
      //获取楼宇
      getbuildings(arr) {
        hlhttp.get({
          url: 'project/buildings',
          data: {
            project_id: arr[0].code
          },
          success: (res) => {
            this.buildings = hlArrayUtil.replaceData(res, [{
              key: 'buildingId',
              rKey: 'code'
            }]);

						if (hlUrlUtil.GetQueryString('buildingId')) {
							this.buildingsSelect = [hlUrlUtil.GetQueryString('buildingId')]
						}

						this.buildings.map(item => {
							if (item.buildingId == this.buildingsSelect[0]) {
								this.buildingId = item.buildingId
								this.buildingName = item.name
							}
						})

            this.searchUnit();
            if (this.curDataPanel == '在租维度') this.buildingStatisticsInfo1()
            if (this.curDataPanel == '签约维度') this.buildingStatisticsInfo2()
            if (this.curDataPanel == '缴费维度') this.buildingStatisticsInfo3()
          }
        })

      },

      //获取楼宇
      getBuildingData() {
        const self = this

        hlhttp.get({
          url: 'project/grouping/_building',
          data: {
            project_id: self.projectId.length ? self.projectId[0] : '#',
            grouping_id: self.groupId || '#'
          },
          success: (data) => {
            data = data.filter(el => el.configState == 'Y')
            self.buildings = hlArrayUtil.replaceData(data, [{
              key: 'buildingId',
              rKey: 'code'
            }]);
            self.buildingsSelect = [data[0].buildingId]

						if (hlUrlUtil.GetQueryString('buildingId')) {
							this.buildingsSelect = [hlUrlUtil.GetQueryString('buildingId')]
						}

						this.buildings.map(item => {
							if (item.buildingId == this.buildingsSelect[0]) {
								this.buildingId = item.buildingId
								this.buildingName = item.name
							}
						})


            self.searchUnit();
            self.getFloor()
            if (self.curDataPanel == '在租维度') self.buildingStatisticsInfo1()
            if (self.curDataPanel == '签约维度') self.buildingStatisticsInfo2()
            if (self.curDataPanel == '缴费维度') self.buildingStatisticsInfo3()

          }
        })
      },

      //选中位置工位
      selectedPosition(item) {
        if (item.rentState == 'ZY') {
          if (item.positionType == 'ST') {
            hl.toast('自用车位不能出租')
          }
          if (item.positionType == 'WP') {
            hl.toast('自用工位不能出租')
          }
          return
        }
        if (this.selectedPositionIds.indexOf(item.positionId) == -1) {
          this.selectedPositionIds.push(item.positionId)
          this.selectedPositionIdInfos.push(item)
        } else {
          this.selectedPositionIds.splice(this.selectedPositionIds.indexOf(item.positionId), 1)
          this.selectedPositionIdInfos.splice(this.selectedPositionIds.indexOf(item.positionId), 1)
        }
      },
      selectDataPanel: function (val) {
        this.curDataPanel = val;
        if (val === '在租维度') this.buildingStatisticsInfo1()
        if (val === '签约维度') this.buildingStatisticsInfo2()
        if (val === '缴费维度') this.buildingStatisticsInfo3()
      },
      previewImage: function (url) {
        var imageExt = ['jpg', 'jpeg', 'png', 'JPG', 'JPEG', 'PNG'];
        var pdfExt = ['pdf', 'PDF'];
        var officeExt = ['docx', 'doc', 'xlsx', 'xls', 'xlt']
        var imageFlag = false;
        var pdfFlag = false;
        var officeFlag = false;

        imageExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) imageFlag = true;
        })

        if (imageFlag) {
          $.imageShow([url])
          return
        }
        pdfExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) pdfFlag = true;
        })
        if (pdfFlag) {
          $.previewPDF(url)
          return
        }

        officeExt.forEach((e, i) => {
          if (url.indexOf(e) !== -1) officeFlag = true
        })
        if (officeFlag) {
          $.previewOffice(url)
          return
        }
        hl.toast('暂不支持该格式')
      },
      showFloorQM: function (i, val) {
        if (val.length < 4) return false;
        if (val) hllayer.tips($($('.floorName')[i]), val)
      },
      hideQM: function () {
        hllayer.closeall()
      },
      // 获取用户所拥有的权限
      getPermission: function () {
        var permission = window.localStorage.getItem('permissions');
        // 新建合同权限
        if (permission.indexOf('c29') == -1) {
          this.createContractFlag = false
        }
        // 查看合同权限
        if (permission.indexOf('c28') == -1) {
          this.checkContractFlag = false
        }
      },
      checkBuilding() {
        if (!this.buildingsSelect.length) {
          hl.toast('至少选择一个楼栋');
          if (this.buildings.length) {
            this.buildingsSelect.push(this.buildings[0].buildingId)
          }
        }
      },


      // 信息看板  在租维度
      buildingStatisticsInfo1: function () {
        var self = this;
        hlhttp.get({
          url: 'building/rent',
          data: {
            building_id: self.buildingsSelect + '',
            b_type: self.selectedBusinessTypes + "" || '#'
          },
          success: function (data) {
            self.buildingMes1 = data;
            // 工位及车位看板数据为0时视图不显示
            if (data.totalWpCount === 0 && data.totalStCount !== 0 || data.totalWpCount !== 0 && data.totalStCount === 0 || data.totalWpCount !== 0 && data.totalStCount !== 0) {
              self.unitkb = true;
            } else {
              self.unitkb = false;
            }
          }
        })
      },
      // 信息看板  签约维度
      buildingStatisticsInfo2: function () {
        console.log('222');


        var self = this;
        hlhttp.get({
          url: 'building/rent/info2',
          data: {
            building_id: self.buildingsSelect + '',
            b_type: self.selectedBusinessTypes + "" || '#'
          },
          success: function (data) {
            self.buildingMes2 = data;
            // 工位及车位看板数据为0时视图不显示
            if (data.totalWpCount === 0 && data.totalStCount !== 0 || data.totalWpCount !== 0 && data.totalStCount === 0 || data.totalWpCount !== 0 && data.totalStCount !== 0) {
              self.unitkb = true;
            } else {
              self.unitkb = false;
            }
          }
        })
      },
      // 信息看板  缴费入驻维度
      buildingStatisticsInfo3: function () {
        var self = this;
        hlhttp.get({
          url: 'building/rent/info3',
          data: {
            building_id: self.buildingsSelect + '',
            b_type: self.selectedBusinessTypes + "" || '#'
          },
          success: function (data) {
            self.buildingMes3 = data;
            // 工位及车位看板数据为0时视图不显示
            if (data.totalWpCount === 0 && data.totalStCount !== 0 || data.totalWpCount !== 0 && data.totalStCount === 0 || data.totalWpCount !== 0 && data.totalStCount !== 0) {
              self.unitkb = true;
            } else {
              self.unitkb = false;
            }
          }
        })
      },
      // 单元数据处理
      getRentingUnitMes: function (data) {
        console.log(data)
        if (data.length === 0) {
          this.unitsData = [];
          this.unitTotalNum = 0;
          this.kzUnitTotalNum = 0;
          this.dqUnitTotalNum = 0;
          this.lvUnitTotalNum = 0;
          this.zyUnitTotalNum = 0;
          return false;
        }
        var self = this;
        self.rratMenu[0].num = 0
        self.rratMenu[1].num = 0
        self.rratMenu[2].num = 0
        self.rratMenu[3].num = 0
        self.rratMenu[4].num = 0
        var kz = [],
          dq = [],
          lv = [],
          zy = [],
          yd = [],
          all = [];

        var unitTotalNum = 0,
          kzUnitTotalNum = 0,
          dqUnitTotalNum = 0,
          lvUnitTotalNum = 0,
          zyUnitTotalNum = 0;
        data.map(function (item) {
          var unitNum = 0;
          var kzUnitNum = 0;
          var dqUnitNum = 0;
          var lvUnitNum = 0;
          var zyUnitNum = 0;
          var ydUnitNum = 0;
          var area = 0,
            kzArea = 0,
            dqArea = 0,
            lvArea = 0,
            zyArea = 0,
            ydArea = 0;
          var kzUnitArr = [],
            dqUnitArr = [],
            lvUnitArr = [],
            zyUnitArr = [],
            ydUnitArr = []
          var obj = {};
          item.units.map(function (_item) {
            var _obj = {};
            unitNum++;
            area = area + _item.unitAcreage;

            if (!_item.childUnits) {
              if (_item.rentState === 'VA') {
                kzUnitNum++
              }
              if (_item.rentState === 'IP') {
                lvUnitNum++
              }
              if (_item.rentState === 'DU') {
                dqUnitNum++
              }
              if (_item.rentState === 'ZY') {
                zyUnitNum++
              }
              if (_item.rentState == 'YD') {
                ydUnitNum++
              }
              if (_item.saleState === 'SALE') {
                self.rratMenu[0].num++
              }
              if (_item.saleState === 'SUB') {
                self.rratMenu[1].num++
              }
              if (_item.saleState === 'SIGN') {
                self.rratMenu[2].num++
              }
              if (_item.saleState === 'LOCK') {
                self.rratMenu[3].num++
              }
              if (_item.saleState == 'IDTFY') {
                self.rratMenu[4].num++
              }
            }

            if (_item.childUnits) {
              if (_item.childUnits.length) {
                if (_item.saleState === 'SALE') {
                  self.rratMenu[0].num++
                }
                if (_item.saleState === 'SUB') {
                  self.rratMenu[1].num++
                }
                if (_item.saleState === 'SIGN') {
                  self.rratMenu[2].num++
                }
                if (_item.saleState === 'LOCK') {
                  self.rratMenu[3].num++
                }
                if (_item.saleState == 'IDTFY') {
                  self.rratMenu[4].num++
                }
                _item.childUnits.map(rratItem => {
                  if (rratItem.rentState === 'VA') {
                    kzUnitNum++
                  }
                  if (rratItem.rentState === 'IP') {
                    lvUnitNum++
                  }
                  if (rratItem.rentState === 'DU') {
                    dqUnitNum++
                  }
                  if (rratItem.rentState === 'ZY') {
                    zyUnitNum++
                  }
                  if (rratItem.rentState == 'YD') {
                    ydUnitNum++
                  }
                })
              }
            }


            if (_item.rentState === 'VA') {
              kzArea = kzArea + _item.unitAcreage;
              kzUnitArr.push(_item)
            }
            if (_item.rentState === 'IP') {
              lvArea = lvArea + _item.unitAcreage;
              lvUnitArr.push(_item)
            }
            if (_item.rentState === 'DU') {
              dqArea = dqArea + _item.unitAcreage;
              dqUnitArr.push(_item)
            }
            if (_item.rentState === 'ZY') {
              zyArea = zyArea + _item.unitAcreage;
              zyUnitArr.push(_item)
            }
            if (_item.rentState == 'YD') {
              ydArea = ydArea + _item.unitAcreage;
              ydUnitArr.push(_item)
            }
          })

          // 重组不同状态下的数据



          if (kzUnitArr.length) {
            kz.push({
              'floorId': item.floorId,
              'floorNum': item.floorNum,
              'floorName': item.floorName,
              'buildingId': item.buildingId,
              'buildingName': item.buildingName,
              'num': kzUnitNum,
              'area': kzArea,
              'units': kzUnitArr,
              'flag': true,
            })
          }
          if (dqUnitArr.length) {
            dq.push({
              'floorId': item.floorId,
              'floorNum': item.floorNum,
              'floorName': item.floorName,
              'buildingId': item.buildingId,
              'buildingName': item.buildingName,
              'num': dqUnitNum,
              'area': dqArea,
              'units': dqUnitArr,
              'flag': true,
            })
          }
          if (lvUnitArr.length) {
            lv.push({
              'floorId': item.floorId,
              'floorNum': item.floorNum,
              'floorName': item.floorName,
              'buildingId': item.buildingId,
              'buildingName': item.buildingName,
              'num': lvUnitNum,
              'area': lvArea,
              'units': lvUnitArr,
              'flag': true,
            })
          }
          if (zyUnitArr.length) {
            zy.push({
              'floorId': item.floorId,
              'floorNum': item.floorNum,
              'floorName': item.floorName,
              'buildingId': item.buildingId,
              'buildingName': item.buildingName,
              'num': zyUnitNum,
              'area': zyArea,
              'units': zyUnitArr,
              'flag': true,
            })

          }
          if (ydUnitArr.length) {
            yd.push({
              'floorId': item.floorId,
              'floorNum': item.floorNum,
              'floorName': item.floorName,
              'buildingId': item.buildingId,
              'buildingName': item.buildingName,
              'num': ydUnitNum,
              'area': ydArea,
              'units': ydUnitArr,
              'flag': true,
            })

          }

          all.push({
            'floorId': item.floorId,
            'floorNum': item.floorNum,
            'floorName': item.floorName,
            'buildingId': item.buildingId,
            'buildingName': item.buildingName,
            'num': unitNum,
            'area': area,
            'units': item.units,
            'flag': true,
          })





          unitTotalNum = unitTotalNum + unitNum;
          kzUnitTotalNum = kzUnitTotalNum + kzUnitNum;
          dqUnitTotalNum = dqUnitTotalNum + dqUnitNum;
          lvUnitTotalNum = lvUnitTotalNum + lvUnitNum;
          zyUnitTotalNum = zyUnitTotalNum + zyUnitNum;
        })

        self.unitTotalNum = unitTotalNum;
        self.kzUnitTotalNum = kzUnitTotalNum;
        self.dqUnitTotalNum = dqUnitTotalNum;
        self.lvUnitTotalNum = lvUnitTotalNum;
        self.zyUnitTotalNum = zyUnitTotalNum;
        var unitsData = {
          'all': self.handlerDatas(all),
          'kz': self.handlerDatas(kz),
          'dq': self.handlerDatas(dq),
          'lv': self.handlerDatas(lv),
          'zy': self.handlerDatas(zy),
        }
        self.unitsData = unitsData;
        console.log(unitsData)
      },

      handlerDatas(arr) {
        console.log(arr)
        let tempArr = [];
        let endData = [];
        for (let i = 0; i < arr.length; i++) {
          if (tempArr.indexOf(arr[i].buildingId) === -1) {
            endData.push({
              buildingId: arr[i].buildingId,
              buildingName: arr[i].buildingName,
              flag: true,
              children: [arr[i]]
            });
            tempArr.push(arr[i].buildingId);
          } else {
            for (let j = 0; j < endData.length; j++) {
              if (endData[j].buildingId == arr[i].buildingId) {
                endData[j].children.push(arr[i]);
                break;
              }
            }
          }
        }
        return endData // 最终输出
      },



      //意向信息
      getCustomerWillsData(id) {
        hlhttp.get({
          url: 'unit/related_intent',
          data: {
            unit_id: id
          },
          success: (res) => {
            this.intentlist = res;
          }
        })
      },
      // 工位车位数据处理  st 车位  wp 工位
      getRentingStWpMes: function (data) {
        console.log(data)
        var self = this;
        if (data.length === 0) {
          self.stData = {
            'all': [],
            'kz': [],
            'dq': [],
            'lv': [],
            'zy': []
          }
          self.wpData = {
            'all': [],
            'kz': [],
            'dq': [],
            'lv': [],
            'zy': []
          }
          // 车位
          this.stTotalNum = 0;
          this.kzStTotalNum = 0;
          this.dqStTotalNum = 0;
          this.lvStTotalNum = 0;
          this.zyStTotalNum = 0;
          // 工位
          this.wpTotalNum = 0;
          this.kzWpTotalNum = 0;
          this.dqWpTotalNum = 0;
          this.lvWpTotalNum = 0;
          this.zyWpTotalNum = 0;
          return false;
        }

        var stData = function (data) {
          console.log(data)
          var kz = [],
            dq = [],
            lv = [],
            zy = [],
            all = [];
          var unitTotalNum = 0,
            kzUnitTotalNum = 0,
            dqUnitTotalNum = 0,
            lvUnitTotalNum = 0,
            zyUnitTotalNum = 0;
          data.map(function (item) {
            var unitNum = 0;
            var kzUnitNum = 0;
            var dqUnitNum = 0;
            var lvUnitNum = 0;
            var zyUnitNum = 0;
            var kzUnitArr = [],
              dqUnitArr = [],
              lvUnitArr = [],
              zyUnitArr = [],
              allUnitArr = [];
            var obj = {};
            item.positions.map(function (_item) {
              var _obj = {};
              if (_item.positionType === 'ST') {
                unitNum++;
                allUnitArr.push(_item)
                if (_item.rentState === 'VA') {
                  kzUnitNum++
                  kzUnitArr.push(_item)
                }
                if (_item.rentState === 'IP') {
                  lvUnitNum++
                  lvUnitArr.push(_item)
                }
                if (_item.rentState === 'DU') {
                  dqUnitNum++
                  dqUnitArr.push(_item)
                }
                if (_item.rentState === 'ZY') {
                  zyUnitNum++
                  zyUnitArr.push(_item)
                }
              }
            })
            // 重组不同状态下的数据
            if (kzUnitArr.length) {
              kz.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': kzUnitNum,
                'positions': kzUnitArr,
                'flag': true
              })
            }
            if (dqUnitArr.length) {
              dq.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': dqUnitNum,
                'positions': dqUnitArr,
                'flag': true
              })
            }
            if (lvUnitArr.length) {
              lv.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': lvUnitNum,
                'positions': lvUnitArr,
                'flag': true
              })
            }
            if (zyUnitArr.length) {
              zy.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': zyUnitNum,
                'positions': zyUnitArr,
                'flag': true
              })
            }
            if (allUnitArr.length) {
              all.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': unitNum,
                'positions': allUnitArr,
                'flag': true
              })
            }


            unitTotalNum = unitTotalNum + unitNum;
            kzUnitTotalNum = kzUnitTotalNum + kzUnitNum;
            dqUnitTotalNum = dqUnitTotalNum + dqUnitNum;
            lvUnitTotalNum = lvUnitTotalNum + lvUnitNum;
            zyUnitTotalNum = zyUnitTotalNum + zyUnitNum;
          })

          self.stTotalNum = unitTotalNum;
          self.kzStTotalNum = kzUnitTotalNum;
          self.dqStTotalNum = dqUnitTotalNum;
          self.lvStTotalNum = lvUnitTotalNum;
          self.zyStTotalNum = zyUnitTotalNum;
          var stData = {
            'all': self.handlerDatas(all),
            'kz': self.handlerDatas(kz),
            'dq': self.handlerDatas(dq),
            'lv': self.handlerDatas(lv),
            'zy': self.handlerDatas(zy),
          }
          // var stData = {
          //   'all': all,
          //   'kz': kz,
          //   'dq': dq,
          //   'lv': lv,
          //   'zy':zy,
          // }
          // console.log(stData)
          self.stData = stData;
        }

        var wpData = function (data) {
          console.log(data)
          var kz = [],
            dq = [],
            lv = [],
            zy = [],
            all = [];
          var unitTotalNum = 0,
            kzUnitTotalNum = 0,
            dqUnitTotalNum = 0,
            lvUnitTotalNum = 0,
            zyUnitTotalNum = 0;
          data.map(function (item) {
            var unitNum = 0;
            var kzUnitNum = 0;
            var dqUnitNum = 0;
            var lvUnitNum = 0;
            var zyUnitNum = 0;
            var kzUnitArr = [],
              dqUnitArr = [],
              lvUnitArr = [],
              zyUnitArr = [],
              allUnitArr = [];
            var obj = {};
            item.positions.map(function (_item) {
              var _obj = {};
              if (_item.positionType === 'WP') {
                unitNum++;
                allUnitArr.push(_item)
                if (_item.rentState === 'VA') {
                  kzUnitNum++
                  kzUnitArr.push(_item)
                }
                if (_item.rentState === 'IP') {
                  lvUnitNum++
                  lvUnitArr.push(_item)
                }
                if (_item.rentState === 'DU') {
                  dqUnitNum++
                  dqUnitArr.push(_item)
                }
                if (_item.rentState === 'ZY') {
                  zyUnitNum++
                  zyUnitArr.push(_item)
                }
              }
            })
            // 重组不同状态下的数据
            if (kzUnitArr.length) {
              kz.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': kzUnitNum,
                'positions': kzUnitArr,
                'flag': true,
              })
            }
            if (dqUnitArr.length) {
              dq.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': dqUnitNum,
                'positions': dqUnitArr,
                'flag': true,
              })
            }
            if (lvUnitArr.length) {
              lv.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': lvUnitNum,
                'positions': lvUnitArr,
                'flag': true,
              })
            }
            if (zyUnitArr.length) {
              zy.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': zyUnitNum,
                'positions': zyUnitArr,
                'flag': true,
              })
            }
            if (allUnitArr.length) {
              all.push({
                'floorId': item.floorId,
                'floorNum': item.floorNum,
                'floorName': item.floorName,
                'buildingId': item.buildingId,
                'buildingName': item.buildingName,
                'num': unitNum,
                'positions': allUnitArr,
                'flag': true,
              })
            }
            unitTotalNum = unitTotalNum + unitNum;
            kzUnitTotalNum = kzUnitTotalNum + kzUnitNum;
            dqUnitTotalNum = dqUnitTotalNum + dqUnitNum;
            lvUnitTotalNum = lvUnitTotalNum + lvUnitNum;
            zyUnitTotalNum = zyUnitTotalNum + zyUnitNum;
          })

          self.wpTotalNum = unitTotalNum;
          self.kzWpTotalNum = kzUnitTotalNum;
          self.dqWpTotalNum = dqUnitTotalNum;
          self.lvWpTotalNum = lvUnitTotalNum;
          self.zyWpTotalNum = zyUnitTotalNum;
          var wpData = {
            'all': self.handlerDatas(all),
            'kz': self.handlerDatas(kz),
            'dq': self.handlerDatas(dq),
            'lv': self.handlerDatas(lv),
            'zy': self.handlerDatas(zy),
          }
          self.wpData = wpData;
        }

        stData(data);
        wpData(data);
      },
      // 用户项目楼宇
      getBuilding: function () {
        return
        var self = this
        hlhttp.get({
          url: 'user/buildings',
          success: function (data) {
            self.projectId = [data[0].projectId]
            self.projectName = data[0].projectName
            self.buildings = hlArrayUtil.replaceData(data, [{
              key: 'buildingId',
              rKey: 'code'
            }]);
            var projectId = hlUrlUtil.GetQueryString('projectId');
            var buildingId = hlUrlUtil.GetQueryString('buildingId');
						console.log(buildingId)

            if (buildingId !== null) {
              var names = null,
                projectName = null;
              for (var i = 0; i < self.buildings.length; i++) {
                if (self.buildings[i].buildingId == buildingId) {
                  names = self.buildings[i].name
                  projectName = self.buildings[i].projectName
                }
              }
              self.selectedBuilding(projectId, buildingId, names, projectName)
            } else {
              self.selectedBuilding(self.buildings[0].projectId, self.buildings[0].buildingId, self.buildings[0].name, self.buildings[0].projectName)
            }
            // 默认选第一项
          }
        })
      },
      // 搜索楼宇单元空置及到期租控信息
      searchUnit: function () {
        var self = this
        hlhttp.get({
          url: 'building/units/_search',
          data: {
            group_id: self.groupId || '#',
            building_id: self.buildingsSelect + '' || '#',
            va_begin_date: self.empty_q || '#',
            va_end_date: self.empty_h || '#',
            du_begin_date: self.deadline_q || '#',
            du_end_date: self.deadline_h || '#',
            b_type: self.selectedBusinessTypes.length ? self.selectedBusinessTypes.join() : '#'
          },
          success: function (data) {
            self.getRentingUnitMes(data)
          }
        })
      },
      // 搜索楼宇车位及工位空置及到期租控信息
      searchWpAndSt: function () {
        var self = this
        hlhttp.get({
          url: 'building/positions/_search',
          data: {
            group_id: self.groupId || '#',
            building_id: self.buildingsSelect + '' || '#',
            va_begin_date: self.empty_q || '#',
            va_end_date: self.empty_h || '#',
            du_begin_date: self.deadline_q || '#',
            du_end_date: self.deadline_h || '#'
          },
          success: function (data) {
            self.getRentingStWpMes(data)
          }
        })
      },
      // 获取不同出租状态下的单元、车位、工位
      getSomeRentStateData: function (val) {
        var self = this;
        self.selectedLeftTabItem = val;
        if (val == '全部') {
          self.unitsKey = 'all';
        }
        if (val == '空置单元') {
          self.unitsKey = 'kz';
        }
        if (val == '即将到期') {
          self.unitsKey = 'dq';
        }
        if (val == '即将履约') {
          self.unitsKey = 'lv';
        }
        if (val == '自用') {
          self.unitsKey = 'zy';
        }


        if (localStorage.getItem('userMes').indexOf('SINOOCEAN') > -1) {
          self.rratMenu[0].num = 0
          self.rratMenu[1].num = 0
          self.rratMenu[2].num = 0
          self.rratMenu[3].num = 0
          self.rratMenu[4].num = 0
          this.unitsData[this.unitsKey].map(item => {
            item.units.map(_item => {
              if (_item.saleState === 'SALE') {
                self.rratMenu[0].num++
              }
              if (_item.saleState === 'SUB') {
                self.rratMenu[1].num++
              }
              if (_item.saleState === 'SIGN') {
                self.rratMenu[2].num++
              }
              if (_item.saleState === 'LOCK') {
                self.rratMenu[3].num++
              }
              if (_item.saleState == 'IDTFY') {
                self.rratMenu[4].num++
              }
            })
          })
        }
      },
      // 获取不同视图  单元、车位、工位
      getSomeView: function (val) {
        var self = this;
        this.rratMenuSelect = []
        self.selectedrightTabItem = val;
        if (val === '车位视图') {
          self.stView = true;
          self.wpView = false;
          self.unitView = false;
          self.pmtView = false;
          self.businessTextFlag = false;
          self.searchWpAndSt();
        }
        if (val === '工位视图') {
          self.wpView = true;
          self.unitView = false;
          self.stView = false;
          self.pmtView = false;
          self.businessTextFlag = false;
          self.searchWpAndSt();
        }
        if (val === '单元视图') {
          self.unitView = true;
          self.stView = false;
          self.wpView = false;
          self.pmtView = false;
          self.businessTextFlag = true;
          // self.searchUnit();
        }
        if (val === '平面图') {
          self.unitView = false;
          self.stView = false;
          self.wpView = false;
          self.pmtView = true;
          self.businessTextFlag = false;
          self.getFloor()
        }
      },
      // 查询
      search: function () {
        if (this.selectedrightTabItem === '平面图') return
        if (this.selectedrightTabItem === '单元视图') {
          this.searchUnit();
        }
        if (this.selectedrightTabItem === '车位视图' || this.selectedrightTabItem === '工位视图') {
          this.searchWpAndSt();
        }
      },
      // 重置
      reset: function () {
        var self = this;
        self.empty_q = ''
        self.empty_h = ''
        self.deadline_q = ''
        self.deadline_h = ''
        if (self.selectedrightTabItem === '单元视图') this.searchUnit()
        if (self.selectedrightTabItem === '车位视图' || self.selectedrightTabItem === '工位视图') this.searchWpAndSt()
      },
      selectedBuilding: function (projectId, buildingId, buildingName, projectName) {
        this.projectId = [projectId];
        this.projectName = projectName;
        this.buildingId = buildingId;
        this.buildingName = buildingName;
        this.buildingsSelect = [buildingId]
        // 获取对应视图的数据
        if (this.curDataPanel == '在租维度') this.buildingStatisticsInfo1()
        if (this.curDataPanel == '签约维度') this.buildingStatisticsInfo2()
        if (this.curDataPanel == '缴费维度') this.buildingStatisticsInfo3()
        this.search();
        this.getFloor()
      },
      //查看单元详情
      getUnitDetails: function (floorId, floorNum, unitId, unitName, unitAcreage, unitType, rentState, contractId, floorName, item, flag) {
        this.isDisplayRentPop = true
        if (flag) {
          this.isDisplayRentPop = false
        }

        this.selectedUnitId = unitId;
        //新的工位车位
        if (unitType === 'ST' || unitType === 'WP') {
          this.stwpFlag = true;
          this.isShowBuUnitDetail = true;
          this.selectedPositionType = unitType
          this.getBuUnitMes('租赁情况')
          this.getPositionDetailMes(unitId, unitType)
          this.rentUnitInfo = {
            projectId: (this.projectIdSelect[0] == '#' || !this.projectIdSelect[0]) ? this.projectId[0] : this.projectIdSelect[0],
            projectName: this.projectName,
            buildingId: this.buildingId,
            buildingName: this.buildingName,
            floorId: floorId,
            floorNum: floorNum,
            floorName: floorName,
            unitId: unitId,
            unitName: unitName,
            unitAcreage: unitAcreage,
            unitType: unitType
          }
          return
        }

        var self = this;
        var permission = window.localStorage.getItem('permissions');
        // 普通单元类型且出租状态为非自用展示单元详情 并存储单元信息在本地
        if (unitType === 'BU' && rentState !== 'ZY') {
          self.isShowBuUnitDetail = true;
          self.getBuUnitMes('房源详情')

          var contractMes = {
            'floor_id': floorId,
            'floor_num': floorNum,
            'floor_name': floorName,
            'unit_name': unitName,
            'unit_acreage': unitAcreage,
            'unit_id': unitId
          }
          window.sessionStorage.setItem('RENT_UNIT_MES', JSON.stringify(contractMes))
        }

        // 车位、联合办公单元类型展示车位或工位详情 并存储单元信息在本地
        var unitMes = {
          'floorId': floorId,
          'floorNum': floorNum,
          'floorName': floorName,
          'unitId': unitId,
          'unitName': unitName
        }

      },
      // 工位前往合同
      wpGoToContract: function (floorId, floorNum, unitId, unitName, positionId, positionName, rentState, contractId, floorName) {
        var self = this;
        // 前往新建合同
        var permission = window.localStorage.getItem('permissions')
        if (permission.indexOf('c29') > -1) {
          if (rentState === 'VA' || rentState == 'YD') {
            var contractMes = {
              'projectId': (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
              'contractType': 'WR',
              'units': {
                'building_id': self.buildingId,
                'building_name': self.buildingName,
                'floor_id': floorId,
                'floor_num': floorNum,
                'floor_name': floorName,
                'unit_name': unitName,
                'unit_id': unitId,
                'stop': [{
                  'stop_id': positionId,
                  'stop_name': positionName
                }]
              }
            }

            hlUrlUtil.goTo('contractNew1', {
              ddtab: true,
              RENT_WP_POSITION_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMes)))
            }, true)
            return
          }
        }
        if (permission.indexOf('c28') > -1) {
          if (rentState !== 'VA' && rentState !== 'ZY') {
            hlUrlUtil.goTo('contractNewDeatil', {
              id: contractId,
              proId: (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
              ddtab: true
            }, false)
          }
        }
      },
      // 车位前往合同
      stGoToContract: function (floorId, floorNum, unitId, unitName, positionId, positionName, rentState, contractId, floorName) {
        var self = this;
        var permission = window.localStorage.getItem('permissions')
        if (permission.indexOf('c29') > -1) {
          if (rentState === 'VA' || rentState == 'YD') {
            var contractMes = {
              'projectId': (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
              'contractType': 'ER',
              'units': {
                'building_id': self.buildingId,
                'building_name': self.buildingName,
                'floor_id': floorId,
                'floor_num': floorNum,
                'floor_name': floorName,
                'unit_name': unitName,
                'unit_id': unitId,
                'stop': [{
                  'stop_id': positionId,
                  'stop_name': positionName
                }]
              }
            }

            hlUrlUtil.goTo('contractNew1', {
              ddtab: true,
              RENT_ST_POSITION_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMes)))
            }, true)
            return
          }
        }
        if (permission.indexOf('c28') > -1) {
          if (rentState !== 'VA' && rentState !== 'ZY') {
            hlUrlUtil.goTo('contractNewDeatil', {
              id: contractId,
              proId: (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
              ddtab: true
            }, true)
          }
        }
      },
      // 单元详情内车位、工位前往合同
      unitPositionGoToContract: function (positionId, positionName, positionType, rentState, contractId) {
        var self = this;
        var unitMes = JSON.parse(window.sessionStorage.getItem('RENT_UNIT_MES'));
        // 工位
        var permission = window.localStorage.getItem('permissions')
        if (positionType === 'WP') {
          if (permission.indexOf('c29') > -1) {
            if (rentState === 'VA') {
              var contractMes = {
                'projectId': (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
                'contractType': 'WR',
                'units': {
                  'building_id': self.buildingId,
                  'building_name': self.buildingName,
                  'floor_id': unitMes.floorId,
                  'floor_num': unitMes.floorNum,
                  'floor_name': unitMes.floorName,
                  'unit_name': unitMes.unitName,
                  'unit_id': unitMes.unitId,
                  'stop': [{
                    'stop_id': positionId,
                    'stop_name': positionName
                  }]
                }
              }
              hlUrlUtil.goTo('contractNew1', {
                ddtab: true,
                RENT_WP_POSITION_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMes)))
              }, true)
            }
          }
          if (permission.indexOf('c28') > -1) {
            if (rentState !== 'VA' && rentState !== 'ZY') {
              hlUrlUtil.goTo('contractNewDeatil', {
                id: contractId,
                proId: (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
                ddtab: true
              }, true)
            }
          }
        }
        // 车位
        if (positionType === 'ST') {
          if (permission.indexOf('c29') > -1) {
            if (rentState === 'VA') {
              var contractMes = {
                'projectId': (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
                'contractType': 'ER',
                'units': {
                  'building_id': self.buildingId,
                  'building_name': self.buildingName,
                  'floor_id': unitMes.floorId,
                  'floor_num': unitMes.floorNum,
                  'floor_name': unitMes.floorName,
                  'unit_name': unitMes.unitName,
                  'unit_id': unitMes.unitId,
                  'stop': [{
                    'stop_id': positionId,
                    'stop_name': positionName
                  }]
                }
              }

              hlUrlUtil.goTo('contractNew1', {
                ddtab: true,
                RENT_ST_POSITION_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMes)))
              }, true)
            }
          }
          if (permission.indexOf('c28') > -1) {
            if (rentState !== 'VA' && rentState !== 'ZY') {
              hlUrlUtil.goTo('contractNewDeatil', {
                id: contractId,
                proId: (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
                ddtab: true
              }, true)
            }
          }
        }
      },
      // 单元详情内普通类型单元前往合同
      buUnitGoToContract: function (num) {

        if (this.selectedPositionType == 'WP' || this.selectedPositionType == 'ST') {
          let positionName = this.selectedPositionType == 'WP' ? '工位' : '车位';
          if (!this.selectedPositionIds.length) {
            hl.toast('请选择' + positionName)
            return
          }
          if (num == 0) {
            let yxCreateData = {
              posotion: this.selectedPositionIdInfos,
              unit: this.rentUnitInfo
            }
            localStorage.setItem('yxCreateData', JSON.stringify(yxCreateData))
            hlUrlUtil.goTo('yxCreate', {
              ddtab: true,
              clear: true
            }, true)
          } else {

            let contractMesData = JSON.parse(JSON.stringify(this.rentUnitInfo))
            contractMesData.stop = [];
            this.selectedPositionIdInfos.map(item => {
              contractMesData.stop.push({
                stop_id: item.positionId,
                stop_name: item.positionName
              })
            })

            hlUrlUtil.goTo('contractNew1', {
              ddtab: true,
              clear: true,
              RENT_WPST_UNIT_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMesData)))
            }, true)
          }
          return
        }

        var self = this;
        var permission = window.localStorage.getItem('permissions');
        var unitMes = JSON.parse(window.sessionStorage.getItem('RENT_UNIT_MES'));

        var contractMes = {
          'projectId': (self.projectIdSelect[0] == '#' || !self.projectIdSelect[0]) ? self.projectId[0] : self.projectIdSelect[0],
          'contractType': 'ER',
          'units': {
            'building_id': self.buildingId,
            'building_name': self.buildingName,
            'floor_id': unitMes.floor_id,
            'floor_num': unitMes.floor_num,
            'floor_name': unitMes.floor_name,
            'unit_name': unitMes.unit_name,
            'unit_acreage': unitMes.unit_acreage,
            'unit_id': unitMes.unit_id
          }
        }

        if (num == 0) {
          hlUrlUtil.goTo('yxCreate', {
            ddtab: true,
            RENT_BU_UNIT_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMes)))
          }, true)
        } else {
          hlUrlUtil.goTo('contractNew1', {
            ddtab: true,
            RENT_BU_UNIT_MES: encodeURIComponent(encodeURIComponent(JSON.stringify(contractMes)))
          }, true)
        }
      },
      // 获取车位及工位详情信息
      getPositionDetailMes: function (unitId, positionType) {
        var self = this;
        hlhttp.get({
          url: 'units/positions',
          data: {
            unit_id: unitId
          },
          success: function (data) {
            self.positionData = data;
          }
        })
      },
      closePositionDetail: function () {
        this.isShowPositionDetail = false;

      },
      closeBuUnitDetail: function () {
        this.isShowBuUnitDetail = false;
        this.stwpFlag = false;
        this.selectedPositionIds = []
        this.selectedPositionIdInfos = []
        this.selectedPositionType = null
      },
      getBuUnitMes: function (item) {
        var self = this;
        if (item === '租赁情况') {
          self.houseInfoFlag = false;
          self.rentFlag = false;
          self.imageFontFlag = false;
          self.contractFlag = false;
          self.fileFlag = false;
          self.yxFlag = false;
          self.intention = false;
          self.selectedbuUnitTabItem = '租赁情况'
        }
        if (item === '在租客户') {
          self.houseInfoFlag = false;
          self.rentFlag = true;
          self.imageFontFlag = false;
          self.intention = false;
          self.contractFlag = false;
          self.fileFlag = false;
          self.yxFlag = false;
          self.selectedbuUnitTabItem = '在租客户'
          self.getRentInfo(self.selectedUnitId)
        }
        if (item === '房源详情') {
          self.houseInfoFlag = true;
          self.rentFlag = false;
          self.imageFontFlag = false;
          self.intention = false;
          self.contractFlag = false;
          self.fileFlag = false;
          self.yxFlag = false;
          self.selectedbuUnitTabItem = '房源详情'
          self.getBuUnitDetails(self.selectedUnitId)
        }
        if (item === '图文描述') {
          self.houseInfoFlag = false;
          self.rentFlag = false;
          self.imageFontFlag = true;
          self.intention = false;
          self.contractFlag = false;
          self.fileFlag = false;
          self.yxFlag = false;
          self.selectedbuUnitTabItem = '图文描述'
        }
        if (item === '初步意向') {
          self.houseInfoFlag = false;
          self.rentFlag = false;
          self.imageFontFlag = false;
          self.intention = true;
          self.contractFlag = false;
          self.fileFlag = false;
          self.yxFlag = false;
          self.selectedbuUnitTabItem = '初步意向'
          self.getintentionList(self.selectedUnitId)
        }
        if (item === '关联合同') {
          self.houseInfoFlag = false;
          self.rentFlag = false;
          self.imageFontFlag = false;
          self.intention = false;
          self.fileFlag = false;
          self.contractFlag = true;
          self.yxFlag = false;
          self.selectedbuUnitTabItem = '关联合同'
          self.getAssociatedContracts(self.selectedUnitId)
        }
        if (item === '相关文件') {
          self.houseInfoFlag = false;
          self.rentFlag = false;
          self.imageFontFlag = false;
          self.intention = false;
          self.fileFlag = true;
          self.contractFlag = false;
          self.yxFlag = false;
          self.selectedbuUnitTabItem = '相关文件'
        }
        if (item === '意向信息') {
          self.houseInfoFlag = false;
          self.rentFlag = false;
          self.imageFontFlag = false;
          self.intention = false;
          self.fileFlag = false;
          self.contractFlag = false;
          self.yxFlag = true;
          self.selectedbuUnitTabItem = '意向信息'
          self.getCustomerWillsData(self.selectedUnitId)
        }
      },
      // 获取普通单元详情信息
      getBuUnitDetails: function (id) {
        var self = this;
        hlhttp.get({
          url: 'unit/info',
          data: {
            'unit_id': id
          },
          success: function (data) {
            self.unitDetails = data;
            self.contractFile = []
            if (data.attachmentNames) {
              var attname = data.attachmentNames.split(',')
              var atturl = data.attachmentUrls.split(',')
              for (var i = 0; i < attname.length; i++) {
                self.contractFile.push({
                  name: attname[i],
                  url: atturl[i]
                })
              }
            }

            var baseFacilityArr = [];
            self.baseFacility.map(function (_item) {
              var obj = {
                'code': _item.code,
                'name': _item.name,
                'selected': false
              }
              baseFacilityArr.push(obj)
            })
            self.baseFacility = baseFacilityArr;
            // 基础设施
            data.facilitys.map(function (item) {
              var facIndex = 0;
              self.baseFacility.map(function (_item) {
                if (item === _item.code) {
                  _item['selected'] = true
                }
                facIndex++;
              })
            })
            // 图片转换
            self.unitPositionImgArr = data.unitPositionImg ? data.unitPositionImg.split() : []
            self.unitPlainImgArr = data.unitPlainImg ? data.unitPlainImg.split() : []
            self.consImgsArr = data.consImgs
            self.innerImgsArr = data.innerImgs
          }
        })
      },
      // 获取在租客户
      getRentInfo(id) {
        hlhttp.get({
          url: 'unit/customer,cincb_info',
          data: {
            unit_id: id
          },
          success: res => {
            this.rentInfo = res
          }
        })
      },
      // 获取基础设施类型列表
      getfacilityTypesData: function () {
        var self = this;
        hlhttp.get({
          url: 'configure/facility/dict',
          success: function (data) {
            var baseFacilityArr = [];
            data.map(function (_item) {
              var obj = {
                'code': _item.dictCode,
                'name': _item.dictName,
                'selected': false
              }
              baseFacilityArr.push(obj)
            })
            self.baseFacility = baseFacilityArr;
          }
        })
      },
      // 获取相关合同
      getAssociatedContracts: function (id) {
        var self = this;
        hlhttp.get({
          url: 'unit/contracts',
          data: {
            'unit_id': id
          },
          success: function (data) {
            self.associatedContracts = data;
          }
        })
      },
      // 大图展示
      showBigImage: function (src) {
        $.imageShow(src.split())
      },
      // 空置到期日期置空
      emptyDate: function (val) {
        if (val == 'KZ') {
          this.deadline_q = ''
          this.deadline_h = ''
        } else {
          this.empty_q = ''
          this.empty_h = ''
        }
      },
      //获取楼层
      getFloor: function (url) {
        var _this = this;
        hlhttp.get({
          url: 'building/floors',
          data: {
            project_id: _this.projectId.length ? _this.projectId[0] : '#',
            building_id: _this.buildingsSelect + '' || '#',
          },
          success: function (res) {
            _this.floorData = res;
            _this.getpmt(res[0].floorId, res[0].plainGraph);
            $('.rent-floor span').text(res[0].floorName)
          }
        })
      },
      //获取平面图
      getpmt: function (id, url) {
        if (id == this.floor_id) return false;
        var _this = this;
        this.imageUrl = url;
        hlhttp.get({
          url: 'floor/units,acerage',
          data: {
            project_id: _this.projectId.length ? _this.projectId[0] : '#',
            floor_id: id,
            building_id: _this.buildingsSelect + '' || '#',
          },
          success: function (res) {
            _this.pmtData = res.units
            _this.addNum = 0
            _this.baseWidth = null;
            _this.baseHeight = null;
            _this.naturalWidth = null;
            _this.naturalHeight = null;
            $('.floor-image').css('width', '945')
            $('.floor-image').css('height', 'auto')
          }
        })
      },
      // 放大缩小时 同比例更新方块大小
      updateSize: function (director) {
        var originRate = director == 'add' ? (1 + (this.addNum - 1) * this.scale) : (1 + (this.addNum + 1) * this.scale);
        var rate = 1 + this.addNum * this.scale;

        $('.drag-drop1').each(function (_index, _item) {
          // 单元比例为1时的基准尺寸为：
          var baseWidth = $(_item).attr('data-width') / originRate
          var baseHeight = $(_item).attr('data-height') / originRate
          var basePadTop = $(_item).attr('data-y') / originRate
          var basePadLeft = $(_item).attr('data-x') / originRate
          var obj = {
            'width': baseWidth * rate,
            'height': baseHeight * rate,
            'paddingTop': basePadTop * rate,
            'paddingLeft': basePadLeft * rate
          }


          $(_item)
            .css({
              'width': obj.width,
              'height': obj.height,
              'transform': 'translate(' + obj.paddingLeft + 'px,' + obj.paddingTop + 'px)'
            })
            .attr('data-x', obj.paddingLeft)
            .attr('data-y', obj.paddingTop)
            .attr('data-width', obj.width)
            .attr('data-height', obj.height)
        })
      },
      // 平面图图形数据
      isIncreaseOrDecreaseFLoorPlan: function (director) {
        var self = this;
        var isChangeSize = function () {
          var imageWidth = $('.floor-image').width();
          var maxWidth = self.naturalWidth;
          if (imageWidth >= maxWidth && director == 'add') {
            hl.toast('平面图已放大至最大值')
            return false;
          }

          var minWidth = self.naturalWidth < self.baseWidth ? self.naturalWidth : self.baseWidth
          if (imageWidth <= minWidth && director == 'reduce') {
            hl.toast('平面图已缩小至最小值')
            return false;
          }
          return true
        }

        if (this.baseWidth) {
          return isChangeSize()
        }
        if (!this.baseWidth) {
          var imgEle = document.querySelector('.floor-image');
          self.baseWidth = $('.floor-image').width();
          self.baseHeight = $('.floor-image').height();
          self.naturalWidth = imgEle.naturalWidth;
          self.naturalHeight = imgEle.naturalHeight;

          return isChangeSize()
        }
      },
      // 放大平面图
      increaseFloorPlan: function () {
        var self = this;
        if (self.isIncreaseOrDecreaseFLoorPlan('add')) {
          self.addNum++;
          $('.floor-image').css('width', self.baseWidth * (1 + self.addNum * self.scale))
          $('.floor-image').css('height', self.baseHeight * (1 + self.addNum * self.scale))
          self.updateSize('add')
        }
      },
      // 缩小平面图
      decreaseFloorPlan: function () {
        var self = this;
        if (self.isIncreaseOrDecreaseFLoorPlan('reduce')) {
          self.addNum--;
          $('.floor-image').css('width', self.baseWidth * (1 + self.addNum * self.scale))
          $('.floor-image').css('height', self.baseHeight * (1 + self.addNum * self.scale))
          self.updateSize('reduce')
        }
      },
      //获取业态类型
      getBusinessTypes: function () {
        var self = this;
        hlhttp.get({
          url: 'unit/business_types',
          success: function (data) {
            var arr = [];
            data.map(function (_item) {
              var obj = {
                'code': _item.code,
                'memo': _item.memo,
                'name': _item.memo,
                'selected': false
              }
              arr.push(obj)
            })
            self.businessTypesList = arr
          }
        })
      },
      // 选中业态
      // selectedYtItem: function (code) {
      //   var self = this;
      //   var index = 0;
      //   var arr = [];

      //   self.businessTypesList.map(function (_item) {
      //     if (_item.code === code) {
      //       if (_item.selected === false) {
      //         arr.push({
      //           'memo': _item.memo,
      //           'code': _item.code,
      //           'selected': true
      //         })
      //         self.selectedBusinessTypes.push(code)
      //       }
      //       if (_item.selected === true) {
      //         arr.push({
      //           'memo': _item.memo,
      //           'code': _item.code,
      //           'selected': false
      //         })
      //         self.selectedBusinessTypes = hlArrayUtil.deleteItem(self.selectedBusinessTypes, _item.code)
      //       }
      //     }
      //     if (_item.code !== code) arr.push(_item)
      //     index++;
      //   })

      //   self.$set(self.$data, 'businessTypesList', arr)
      // },
      // 清空业态
      clearAllBusiness: function () {
        var arr = []
        this.selectedBusinessTypes = [];
        this.businessTypesList.map(function (_item) {
          arr.push({
            'code': _item.code,
            'memo': _item.memo,
            'selected': false
          })
        })
        this.businessTypesList = arr
      },
      confirmBusiness: function () {
        this.searchUnit()
        this.businessFlag = false;
      },
      cancelBusiness: function () {
        this.businessFlag = false;
      },
      toggleBusinessBar: function () {
        this.businessFlag = true;
      },
      // 平面图全屏展示
      showFullScreen: function () {
        window.sessionStorage.setItem('RENT_FLOOR_PLAN_IMAGE', this.imageUrl)
        window.sessionStorage.setItem('RENT_FLOOR_PLAN_DATA', JSON.stringify(this.pmtData))
        hlUrlUtil.goTo('floorPlan', {
          ddtab: true
        }, true)
      },
      // 展示来源于首页的跳转信息  (恶心的地方)
      showMesFromHome() {
        const rentState = hlUrlUtil.GetQueryString('rentState')
        const rentPosition = hlUrlUtil.GetQueryString('rentPosition')

        if (rentState == 'VA') {
          $('.rent-tab-container ul').eq(0).find('li').eq('1').trigger('click')
        }
        if (rentState == 'DU') {
          $('.rent-tab-container ul').eq(0).find('li').eq('2').trigger('click')
        }
        if (rentState == 'IP') {
          $('.rent-tab-container ul').eq(0).find('li').eq('3').trigger('click')
        }
        $('.rent-tab-container ul').eq(1).find('li').eq(hlUrlUtil.GetQueryString('rentPosition')).trigger('click')

      },
      // 获取一级组合数据
      getGroupPrimaryData(data) {
        console.log(data)
        const self = this
        self.projectId = [data[0].code]
        self.projectName = data[0].projectName
        self.groupId = null
        self.buildingId = ''
        self.floorId = ''
        self.unitId = ''
        self.buildingList = []
        self.floorList = []
        self.unitList = []
        self.selectedGroupData = []

        self.getGroupData().then(data => {
          self.groupOneData = hlArrayUtil.replaceData(data, [{
            key: 'id',
            rKey: 'code'
          }]);

          self.selectedGroupData.push(data[0]['name'])
          self.groupId = data[0].id
          self.getBuildingData()
        })

      },
      // 获取初步意向列表数据
      getintentionList(id){
        hlhttp.get({
          url: 'contract/initials',
          data: {
            'unit_id':id
          },
          success:(data)=> {
            this.intentionList = data
          }
        })
      },
      // 选取一级组合数据
      selectOneGroup(res) {
        // console.log(this.selectedGroupData);
        console.log(res);
        const self = this
        this.groupId = res['cur']['code']
        this.getGroupData().then(data => {
          self.groupTwoData = hlArrayUtil.replaceData(data, [{
            key: 'id',
            rKey: 'code'
          }])
          self.getBuildingData()
        })
      },
      // 选取二级组合数据
      selectTwoGroup(res) {
        const self = this
        this.groupId = res['cur']['code']
        this.getGroupData().then(data => {
          self.groupThreeData = hlArrayUtil.replaceData(data, [{
            key: 'id',
            rKey: 'code'
          }])
          self.getBuildingData()
        })
      },
      // 选取三级组合数据
      selectThreeGroup(res) {
        this.groupId = res['cur']['code']
      },
      gotoDetail(id){
        hlUrlUtil.goTo('customerDetails', { id: id,ddtab:'true',page:'customerManagement' }, true)
      },
      getGroupData() {
        const self = this

        return new Promise(resolve => {
          hlhttp.get({
            url: 'project/grouping_info/_subclass',
            data: {
              'project_id': self.projectId[0],
              'grouping_id': self.groupId || '#'
            },
            success: function (data) {
              resolve(data)
            }
          })
        })
      },
      searchByGroup() {
        this.search()
        this.buildingStatisticsInfo1()
        this.buildingStatisticsInfo2()
        this.buildingStatisticsInfo3()
      },
      resetByGroup() {
        this.projectIdSelect = [this.projectList[0].projectId]
        this.getGroupPrimaryData([this.projectList[0]])
        this.selectedBusinessTypes = []
      },

			//根据顶部项目楼栋赋值
			// 1 项目
			// 2 楼宇
			fromToHemoParams (num, value) {
				if (hlUrlUtil.GetQueryString('projectId') && num == 1) {
					this.projectIdSelect = [hlUrlUtil.GetQueryString('projectId')]
				}
				if (!hlUrlUtil.GetQueryString('projectId') && num == 1) {
					this.projectIdSelect = [value]
				}

				if (hlUrlUtil.GetQueryString('buildingId') && num == 2) {
					this.projectIdSelect = [hlUrlUtil.GetQueryString('buildingId')]
				}
				if (!hlUrlUtil.GetQueryString('buildingId') && num == 2) {
					this.projectIdSelect = [value]
				}
			},
    },
    mounted: function () {
      // this.buildingStatisticsInfo2()
      this.getBusinessTypes()
      this.getfacilityTypesData()
      this.getProject()
      this.getPermission()
      this.getDecorationtypes()
      hlSelectUi()

      if (this.permissions.indexOf('c201') == -1) {
        this.buUnitPopTab = ['房源详情', '在租客户', '图文描述', '关联合同', '相关文件']
      }
    }
  })

}())
